package com.cheer.dao;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cheer.entity.ReferencePlacesEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 参评名额
 * 
 * @author chufangzheng
 * @email 1280251739@qq.com
 * @date 2022-02-20 11:41:00
 */
@Mapper
public interface ReferencePlacesDao extends BaseMapper<ReferencePlacesEntity> {


    default List<ReferencePlacesEntity> selectByVatageAndOrgId(List<Long> accountIds, String vatage){

        QueryWrapper<ReferencePlacesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ReferencePlacesEntity::getVintage, vatage).in(ReferencePlacesEntity::getOrgId, accountIds);
        return selectList(queryWrapper);
    }

    Integer countByOrgPath( @Param("orgPath") String orgPath, @Param("vintage") String vintage );

    default ReferencePlacesEntity getByOrgId(Long orgId){

        QueryWrapper<ReferencePlacesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ReferencePlacesEntity::getOrgId, orgId)
                .in(ReferencePlacesEntity::getVintage, DateUtil.format(new Date(),"yyyy"));

        return selectOne(queryWrapper);
    }

}
